package boardStructure;

public class Board {

	private Cell[][] cellTable;
	private final int PREFERRED_TABLE_SIZE = 10;
	private int numOfCellsVertical = PREFERRED_TABLE_SIZE;
	private int numOfCellsHorizontal = PREFERRED_TABLE_SIZE;
	
	public Board(){
		cellTable = new Cell[PREFERRED_TABLE_SIZE][PREFERRED_TABLE_SIZE];
				
	}
	public Board(int _numberOfColumns, int _numberOfRows){
		numOfCellsVertical = _numberOfRows;
		numOfCellsHorizontal = _numberOfColumns;
		
		cellTable = new Cell[numOfCellsHorizontal][numOfCellsVertical];
		
		for( int i = 0 ; i < numOfCellsHorizontal; i++){
			for( int j = 0 ; j < numOfCellsVertical ; j++){
				cellTable[i][j] = new Cell();	
			}
		}
	}
	
	
	public int getNumOfCellsHorizontal(){
		return numOfCellsHorizontal;
	}
	
	public int getNumOfCellsVertical(){
		return numOfCellsVertical;
	}
	
	public synchronized boolean isCellAlive(int xCell, int yCell){
			return cellTable[xCell][yCell].isAlive();
	}
	
	public synchronized void  setCellAlive(int xCell, int yCell, boolean alive){
			cellTable[xCell][yCell].setAlive(alive);
		
	}
	public synchronized void copy(Board sourceBoard){
		
		for( int i = 0; i < numOfCellsHorizontal; i++){
			for( int j = 0; j < numOfCellsVertical; j ++){
				this.setCellAlive(i, j, sourceBoard.isCellAlive(i, j));
			}
		}
		
	}
	public synchronized void resetBoard(boolean isAlive){
		for( int i = 0; i < numOfCellsHorizontal; i++){
			for( int j = 0; j < numOfCellsVertical; j ++){
				this.setCellAlive(i, j, isAlive);
			}
		}
	}
	public synchronized void show(){
		System.out.println("Tablica:");
		for( int i = 0; i < numOfCellsHorizontal; i++){
			for( int j = 0; j < numOfCellsVertical; j ++){
				if(cellTable[i][j].isAlive()) System.out.print("1");
				else System.out.print("_");
			}
			System.out.println("");
		}
	}
	
}
